<?php

/**
 * Epart Schedule Plugin Basic 라이브러리
 *
 * @package epartschedule
 */

/**
 * 현재플러그인정보를 반환한다.
 *
 * @since 0.2
 * @return array 플러그인정보
 */
function schedule_get_plugin_info() {
    $default_header = array(
        'Version' => 'Version'
    );    
    return $plugin_info = get_file_data(WP_PLUGIN_DIR."/".constant(EPART_SCHEDULE_NAME_U."_PLUGIN_DIR_NAME") . "/".EPART_SCHEDULE_NAME."-init.php", $default_header);
}

/**
 * 플러그인 업데이트 안내창을 표시한다.
 *
 * @since 0.2
 */
function schedule_version_warning() {
    //if (isset($_GET["page"]) && $_GET["page"] == "ebbs-admin") {
    if (is_super_admin ()) {
        //최초에 옵션이 없을 경우 기본 버전 세팅한다.
        add_option(EPART_SCHEDULE_NAME."_options", array(
            "version" => "0.0.1"
        ));
        //옵션테이블의 버전값이 플러그인 버전보다 낮으면 업데이트 메세지를 띄움
        $plugin_info = schedule_get_plugin_info();
        $plugin_options = get_option(EPART_SCHEDULE_NAME."_options");
        if (version_compare($plugin_info['Version'], $plugin_options["version"], ">")) {
            //안내메세지
            echo "<div id='".EPART_SCHEDULE_NAME."_admin_warning' class='updated fade'>
                <p>";
            if (isset($_GET["page"]) && $_GET["page"] == EPART_SCHEDULE_NAME."-admin") {
                echo "일정관리 플러그인이 업데이트 되었습니다. 적용하려면 우측의 업데이트버튼을 클릭해주세요. <button id=\"".EPART_SCHEDULE_NAME."_do_update_btn\" class=\"button\">업데이트 실행</button>";
            }else{                
                echo "일정관리 플러그인이 업데이트 되었습니다. <a href='". get_bloginfo("wpurl") ."/wp-admin/admin.php?page=".EPART_SCHEDULE_NAME."-admin' class='button'>일정관리 플러그인 관리로 이동</a>";
            }
            echo "</p>
            </div>";
        }
    }
}

//wp_ajax_xxxxx 관련 실행 함수는 전역범위에서 후크해줘야 함
//admin_ajax.php 파일이 관리자 전체에서 사용되기 때문인듯 하나 정확한 이유는 모르겠음.
add_action("wp_ajax_".EPART_SCHEDULE_NAME."-version-update", EPART_SCHEDULE_NAME."_version_update_callback");
add_action("wp_ajax_".EPART_SCHEDULE_NAME."-update-day", EPART_SCHEDULE_NAME."_update_day_callback");
add_action("wp_ajax_".EPART_SCHEDULE_NAME."-category-del", EPART_SCHEDULE_NAME."_category_del_callback");
add_action("wp_ajax_".EPART_SCHEDULE_NAME."-category-update", EPART_SCHEDULE_NAME."_category_update_callback");
add_action("wp_ajax_".EPART_SCHEDULE_NAME."-category-add", EPART_SCHEDULE_NAME."_category_add_callback");

/**
 * action : schedule-category-update 에 해당하는 콜백 펑션<br />
 * 카테고리 추가
 *
 * @since 0.2
 */
function schedule_category_add_callback() {
    //nonce 검증
    check_ajax_referer(EPART_SCHEDULE_NAME."-category-add-nonce");

    global $wpdb;
    header("Content-Type: application/json");
    if (tx_begin ()) {
        try {
            $wpdb->insert("wp_".EPART_SCHEDULE_NAME."_category", array(
                "ev_catename" => $_POST["ev_catename"]
               ,"ev_blogid"  => get_current_blog_id()
            ));

            tx_commit();
            die(json_encode(array("success" => true,"ev_cateno"=>$wpdb->insert_id,"ev_catename"=>$_POST["ev_catename"])));
        } catch (Exception $exc) {
            tx_rollback("카테고리 추가에 실패했습니다.");
            die(json_encode(array("success" => false)));
        }
    }
}

/**
 * action : schedule-category-update 에 해당하는 콜백 펑션<br />
 * 카테고리 수정
 *
 * @since 0.2
 */
function schedule_category_update_callback() {
    //nonce 검증
    check_ajax_referer(EPART_SCHEDULE_NAME."-category-update-nonce");

    global $wpdb;
    header("Content-Type: application/json"); 
    if (tx_begin ()) {
        try {           
            $wpdb->update("wp_".EPART_SCHEDULE_NAME."_category", array(
                "ev_catename" => $_POST["ev_catename"]
                ), array(
                'ev_cateno' => $_POST["ev_cateno"]
            ));

            tx_commit();
            die(json_encode(array("success" => true)));
        } catch (Exception $exc) {            
            tx_rollback("카테고리 수정에 실패했습니다.");
            die(json_encode(array("success" => false)));
        }
    }
}

/**
 * action : schedule-category-del 에 해당하는 콜백 펑션<br />
 * 카테고리 삭제
 *
 * @since 0.2
 */
function schedule_category_del_callback() {
    //nonce 검증
    check_ajax_referer(EPART_SCHEDULE_NAME."-category-del-nonce");

    global $wpdb;
    header("Content-Type: application/json");
    if (tx_begin ()) {
        try {
            $wpdb->query("DELETE FROM wp_".EPART_SCHEDULE_NAME."_category WHERE ev_cateno = " . $_POST["ev_cateno"]);
            tx_commit();
            die(json_encode(array("success" => true)));
        } catch (Exception $exc) {
            tx_rollback("카테고리를 삭제하지 못하였습니다.");
            die(json_encode(array("success" => false)));
        }
    }
}


/**
 * action : schedule-update-day 에 해당하는 콜백 펑션<br />
 * 이벤트 drag and drop으로 수정된 것을 처리한다.
 *
 * @since 0.2
 */
function schedule_update_day_callback() {
    //nonce 검증
    check_ajax_referer(EPART_SCHEDULE_NAME."-update-day-nonce");

    global $wpdb;
    header("Content-Type: application/json");    
    if (tx_begin ()) {
        try {
            $wpdb->update("wp_".EPART_SCHEDULE_NAME, array(
                "ev_startday"  => $_POST["ev_startday"]
                , "ev_endday"   => $_POST["ev_endday"]
                ), array(
                'ev_no' => $_POST["ev_no"]
            ));            
            tx_commit();
            die(json_encode(array("success" => true)));
        } catch (Exception $exc) {
            tx_rollback("일정 수정에 실패했습니다.");
            die(json_encode(array("success" => false)));
        }
    }
}


/**
 * action : ebbs-version-update 에 해당하는 콜백 펑션<br />
 * 플러그인 업데이트를 수행한다.
 *
 * @since 0.2
 */
function schedule_version_update_callback() {
    $plugin_info = schedule_get_plugin_info();

    //nonce 검증
    check_ajax_referer(EPART_SCHEDULE_NAME."-version-update-nonce");

    //플러그인 업데이트 권한 확인
    header("Content-Type: application/json");    
    if (current_user_can("manage_network")) {        
        //업데이트        
        schedule_plugin_activate();
        
        //버전이 동일해지면 true 출력
        $plugin_options = get_option(EPART_SCHEDULE_NAME."_options");

        if (version_compare($plugin_info['Version'], $plugin_options["version"], "=")) {
            die(json_encode(array("success" => true)));
        } else {
            die(json_encode(array("success" => false)));
        }
    } else {
        die(json_encode(array("success" => false)));
    }
}

/**
 * url rewrite rule 추가
 *
 * @author cwsong
 * @param array $rules 전역 url rewrite rules
 * @since 0.1
 * @return array url rewrite rule이 추가된 rule배열
 */
function schedule_add_url_rewrite_rule($rules) {
    
    $newRules = array();
    //카테고리번호 받기
    //$newRules[EPART_SCHEDULE_NAME."/cateno/([0-9]+)$"] = "index.php?pagename=".EPART_SCHEDULE_NAME."&cateno=\$matches[1]";

    //년, 월 값 받기
    $newRules[EPART_SCHEDULE_NAME."/([0-9]{4})/([0-9]{2})$"] = "index.php?pagename=".EPART_SCHEDULE_NAME."&s_year=\$matches[1]&s_mon=\$matches[2]";
    
    //날짜별 이벤트 상세보기
    $newRules[EPART_SCHEDULE_NAME."/([0-9]{4})/([0-9]{2})/([0-9]{2})$"] = "index.php?pagename=".EPART_SCHEDULE_NAME."&s_year=\$matches[1]&s_mon=\$matches[2]&s_day=\$matches[3]";
    
    return $newRules + $rules;
}

/**
 * 추가할 get 파라메터를 정의한다.
 *
 * @author cwsong
 * @since 0.1
 * @param array $vars 전역으로 정의된 get변수명 배열
 * @return array 플러그인에서 추가할 get변수가 추가된 배열
 */
function schedule_add_query_vars($vars) {
    
    $vars[] = "s_year";
    $vars[] = "s_mon";
    $vars[] = "s_day";
    
    return $vars;
}

/**
 * get 파라메터값을 구한다. 없으면 디폴트 값을 반환한다.<br />
 * 디폴트값을 넣지 않았을 경우 키에 매치되는 값이 없으면 null을 반환한다.
 *
 * @author cwsong
 * @since 0.1
 * @param string $var get_query_var로 구할 변수 키값
 * @param int $defaultVal 디폴트값
 * @return object get 파라메터의 값
 */
function schedule_get_query_var($var, $defaultVal = null) {
    $temp = get_query_var($var);
    if ($temp != null && $temp != "") {
        return $temp;
    }
    return $defaultVal;
}

/**
 * 사용자 페이지
 *
 * @author cwsong
 * @since 0.2
 * @param array $params shortcode 세팅 파라메터
 * @return string 페이지콘텐츠내용
 */
function schedule_do_shortcode($params) {
    $result = '<div id="'.EPART_SCHEDULE_NAME.'-wrapper">';

    $cateno = schedule_get_query_var("cateno");    

    ob_start();
   
    //include_once constant(EPART_SCHEDULE_NAME_U."_PLUGIN_DIR") . "/".EPART_SCHEDULE_NAME."-calendar-script-ver.php";
    include_once constant(EPART_SCHEDULE_NAME_U."_PLUGIN_DIR") . "/".EPART_SCHEDULE_NAME."-calendar.php";
   
    $result .= ob_get_contents();
    ob_end_clean();

    $result .= '</div>';
    return $result;
}

/**
 * 플러그인 활성화 후크함수<br />
 *
 * 플러그인 최초 활성화시 테이블을 생성한다.<br />
 * 스키마 구조변경시 ebbs-init.php의 플러그인 헤더의 버전(Version: 0.x.x)을 업해주거나,<br />
 *
 * @author cwsong
 * @since 0.2
 * @global object $wpdb 워드프레스 DB관리 객체
 */
function schedule_plugin_activate() {
    
    if (is_super_admin()) {        
        global $wpdb; //, $user_level, $wpforumadmin;

        $plugin_table_name = "wp_".EPART_SCHEDULE_NAME;
        $plugin_category_table_name = $plugin_table_name."_category";
        $plugin_info = schedule_get_plugin_info();
        $plugin_options = get_option(EPART_SCHEDULE_NAME."_options");
        $needsUpdate = version_compare($plugin_info["Version"], $plugin_options["version"], ">");

        if ($needsUpdate) {            
            //dbDelta사용하기 위해 인클루드
            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
            $progress_default_field = '';
            $plugin_table_query = "
                 CREATE TABLE {$plugin_table_name} (
                  ev_no int(11) NOT NULL auto_increment COMMENT '행번호 PK',
                  ev_blogid int(10) NOT NULL COMMENT '아이디',
                  ev_title varchar(255) NOT NULL COMMENT '제목',
                  ev_startday datetime NOT NULL COMMENT '시작일',
                  ev_endday datetime NOT NULL COMMENT '종료일',
                  ev_location varchar(255) NOT NULL COMMENT '장소',
                  ev_color varchar(25) NOT NULL COMMENT '배경색',
                  ev_content text NOT NULL COMMENT '내용',
                  ev_repeat int(1) NOT NULL COMMENT '반복',
                  ev_cateno int(10) NOT NULL COMMENT '카테고리번호 FK',
                  PRIMARY KEY  (ev_no),
                  FOREIGN KEY (ev_cateno) REFERENCES wp_schedule_category (ev_cateno) ON DELETE CASCADE ON UPDATE NO ACTION
                ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
              ";           
            //일정데이터 테이블 생성
            dbDelta($plugin_table_query);
            
            $plugin_category_table_query = "
                 CREATE TABLE {$plugin_category_table_name} (
                  ev_cateno int(11) NOT NULL auto_increment COMMENT '행번호 PK',
                  ev_catename varchar(150) NOT NULL COMMENT '카테고리이름',
                  ev_blogid int(10) NOT NULL COMMENT '아이디',
                  PRIMARY KEY  (ev_cateno)
                ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
              ";
            //카테고리 테이블 생성
            dbDelta($plugin_category_table_query);

            //플러그인 버전을 업데이트
            if ($needsUpdate) {                
                $plugin_options["version"] = $plugin_info['Version'];
                update_option(EPART_SCHEDULE_NAME."_options", $plugin_options);
            }
        }
    }
}

/**
 * 플러그인 비활성화후크 실행 함수
 *
 * @author cwsong
 * @since 0.1
 */
function schedule_plugin_deactivate() {

}


/**
 * 사용자 헤더에 플러그인에서 필요한 스타일시트를 로드한다.
 *
 * @author bskim
 * @since 0.1
 */
function schedule_user_print_style(){

    if(get_query_var("pagename") == EPART_SCHEDULE_NAME){
        wp_enqueue_style("jqueryui_css", WP_PLUGIN_URL . "/epart-common/css/jquery-ui-1.8.11.custom.css");
        wp_enqueue_style("fullcalendar_css", constant(EPART_SCHEDULE_NAME_U."_PLUGIN_CSS_URL") . "/"."fullcalendar.css");
        wp_enqueue_style("colorpicker_css", WP_PLUGIN_URL . "/epart-common/css/colorpicker.css");
        wp_enqueue_style("user_css", WP_PLUGIN_URL . "/epart-schedule/css/schedule-user.css");
    }
}

/**
 * 사용자 헤더에 플러그인에서 필요한 스크립트를 로드한다.
 *
 * @author bskim
 * @since 0.1
 */
function schedule_user_print_script(){

    if(get_query_var("pagename") == EPART_SCHEDULE_NAME){
        wp_enqueue_script("jquery");
        wp_enqueue_script("jqueryui_script_handle",WP_PLUGIN_URL . "/epart-common/js/jquery-ui-1.8.11.custom.min.js");
        wp_enqueue_script("fullcalendar_script_handle", constant(EPART_SCHEDULE_NAME_U."_PLUGIN_JS_URL") . "/"."fullcalendar.min.js");
        wp_enqueue_script("colorpicker_script_handle", WP_PLUGIN_URL . "/epart-common/js/colorpicker.js");
        wp_enqueue_script("user_script_handle", WP_PLUGIN_URL . "/epart-schedule/js/schedule-user.js");
        wp_enqueue_script("formatdate_script_handle", WP_PLUGIN_URL . "/epart-schedule/js/formatdate.js");
    }
}

/*
 * 카테고리 추출
 *
 * @author bskim
 * @since 0.1
 * @global wpdb $wpdb 워드프레스 디비매니저클래스
 * @return object 카테고리 리스트
 */
function get_category_list(){
     global $wpdb;

     return $wpdb->get_results("SELECT * FROM wp_".EPART_SCHEDULE_NAME."_category WHERE ev_blogid = '".  get_current_blog_id()."'");
}

/*
 * 일정 추출
 *
 * @author bskim
 * @since 0.1
 * @global wpdb $wpdb 워드프레스 디비매니저클래스
 * @return array 해당월 이벤트 배열
 */
function schedule_user_get_events($year, $mon) {
    global $wpdb;
    $user_events = array();
    //$result_obj = $wpdb->get_results("SELECT * FROM wp_".EPART_SCHEDULE_NAME." WHERE ev_blogid = '".  get_current_blog_id()."' and (date_format(ev_startday,'%Y%m') = '".$year.$mon."' or date_format(ev_endday,'%Y%m') = '".$year.$mon."') order by ev_startday");
    $result_obj = $wpdb->get_results("SELECT * FROM wp_".EPART_SCHEDULE_NAME." WHERE ev_blogid = '".  get_current_blog_id()."' ORDER BY ev_startday");    

    foreach($result_obj as $row){

        // 주간반복
        /*
        if( $row->ev_repeat == 1 ){
            $start_timestampe_w = strtotime($row->ev_startday);
            $end_timestampe_w = strtotime($row->ev_endday);

            $firstday_month = strtotime($year."-".$mon."-01");
            $lastday_month = strtotime($year."-".$mon."-".date(t, mktime(0, 0, 1, $mon, 1, $year)));

            //이전(날짜계산방식)
            $condition_timestampe = $start_timestampe_w;
            while($condition_timestampe >= $firstday_month) {
                $before_week_start = mktime(date("H", $start_timestampe_w), date("i", $start_timestampe_w),date("s", $start_timestampe_w), date("m", $start_timestampe_w), date("d", $start_timestampe_w)-7, date("Y", $start_timestampe_w));
                $before_week_end = mktime(date("H", $end_timestampe_w), date("i", $end_timestampe_w),date("s", $end_timestampe_w), date("m", $end_timestampe_w), date("d", $end_timestampe_w)-7, date("Y", $end_timestampe_w));

                if( $before_week_start <= $lastday_month ) {

                    $first_time = true;
                    $before_week_start_nextday = $before_week_start;
                    $before_week_end_nextday = $before_week_end;
                    while($before_week_start_nextday <= $before_week_end_nextday ){
                        $arrkey = str_replace( "-", "", date("Y-m-d", $before_week_start_nextday) );

                        $next_timestamp = mktime(date("H", $before_week_start_nextday), date("i", $before_week_start_nextday),date("s", $before_week_start_nextday), date("m", $before_week_start_nextday), date("d", $before_week_start_nextday)+1, date("Y", $before_week_start_nextday));
                        $before_week_start_nextday = $next_timestamp;
                        $user_events[$arrkey][$row->ev_no]["title"] = $row->ev_title;
                        $user_events[$arrkey][$row->ev_no]["color"] = $row->ev_color;

                        $order_val = count($user_events[$arrkey]);

                        $first_time = false;
                        $user_events[$arrkey][$row->ev_no]["order"] = $order_val;
                    }
                }

                $start_timestampe_w = $before_week_start;
                $end_timestampe_w = $before_week_end;
                $condition_timestampe = mktime(date("H", $before_week_start), date("i", $before_week_start),date("s", $before_week_start), date("m", $before_week_start), date("d", $before_week_start)-7, date("Y", $before_week_start));
           }

           // 이후 (날짜계산방식)
           $start_timestampe_w2 = strtotime($row->ev_startday);
           $end_timestampe_w2 = strtotime($row->ev_endday);

           $condition_timestampe2 = $start_timestampe_w2;
           while($condition_timestampe2 <= $lastday_month) {
               $next_week_start = mktime(date("H", $start_timestampe_w2), date("i", $start_timestampe_w2),date("s", $start_timestampe_w2), date("m", $start_timestampe_w2), date("d", $start_timestampe_w2)+7, date("Y", $start_timestampe_w2));
               $next_week_end = mktime(date("H", $end_timestampe_w2), date("i", $end_timestampe_w2),date("s", $end_timestampe_w2), date("m", $end_timestampe_w2), date("d", $end_timestampe_w2)+7, date("Y", $end_timestampe_w2));

               if( $next_week_start >= $firstday_month ) {
                    $first_time = true;
                    $next_week_start_nextday = $next_week_start;
                    $next_week_end_nextday = $next_week_end;
                    while($next_week_start_nextday <= $next_week_end_nextday ){
                        $arrkey = str_replace( "-", "", date("Y-m-d", $next_week_start_nextday) );

                        $next_timestamp = mktime(date("H", $next_week_start_nextday), date("i", $next_week_start_nextday),date("s", $next_week_start_nextday), date("m", $next_week_start_nextday), date("d", $next_week_start_nextday)+1, date("Y", $next_week_start_nextday));
                        $next_week_start_nextday = $next_timestamp;
                        $user_events[$arrkey][$row->ev_no]["title"] = $row->ev_title;
                        $user_events[$arrkey][$row->ev_no]["color"] = $row->ev_color;
                        
                        $order_val = count($user_events[$arrkey]);

                        $first_time = false;
                        $user_events[$arrkey][$row->ev_no]["order"] = $order_val;
                    }
               }

               $start_timestampe_w2 = $next_week_start;
               $end_timestampe_w2 = $next_week_end;
               $condition_timestampe2 = mktime(date("H", $next_week_start), date("i", $next_week_start),date("s", $next_week_start), date("m", $next_week_start), date("d", $next_week_start)+7, date("Y", $next_week_start));
           }
        }
        */
        $start_timestampe = strtotime($row->ev_startday);
        $end_timestampe = strtotime($row->ev_endday);
        
        $first_time = true; // order 값을 처음만 1로 넣고 나머진 이전 row의 order+1 로 넣기 위해
        $before_arrkey = "";
        while($start_timestampe <= $end_timestampe){
            $arrkey = str_replace( "-", "", date("Y-m-d", $start_timestampe) );

            $next_timestamp = mktime(date("H", $start_timestampe), date("i", $start_timestampe),date("s", $start_timestampe), date("m", $start_timestampe), date("d", $start_timestampe)+1, date("Y", $start_timestampe));
            $start_timestampe = $next_timestamp;
            $user_events[$arrkey][$row->ev_no]["title"] = $row->ev_title;
            $user_events[$arrkey][$row->ev_no]["color"] = $row->ev_color;

           
            if($first_time){
                $order_val = count($user_events[$arrkey]);
                $order_arr = array();
                foreach( $user_events[$arrkey] as $temparr){
                    $order_arr[] = $temparr["order"];
                }                
            }else{
                $order_val = $user_events[$before_arrkey][$row->ev_no]["order"];
            }     
            
            $first_time = false;
            $user_events[$arrkey][$row->ev_no]["order"] = $order_val;

            $before_arrkey = $arrkey;
       }
        
    }
    return $user_events;
}

/*
 * 달력상에 보여줄 title 생성한다.
 *
 * @author bskim
 * @since 0.1
 * @return stirng title 문자열
 */
function schedule_user_get_event_title($eventarr) {
    $event_title = "";

    if( is_array($eventarr) ){
        $is_first_time = true; // 첫 일정일때만 margin-top적용 하기 위해
        foreach($eventarr as $val){

           $margintop_val = 0;
           if( $is_first_time ){
               $margintop_val = ($val['order']-1)*20;
           }           
           $event_title .= "<div style=\"margin-top:".$margintop_val."px;background-color:".$val['color'].";\">".ep_text_cut($val['title'],5,"..")."</div>";
           $is_first_time = false;
        }        
    }
    
    return $event_title;
}

/*
 * 해당 날짜 일정 상세 정보 추출한다.
 *
 * @author bskim
 * @since 0.1
 * @param string $s_year 연도
 * @param string $s_mon 월
 * @param string $s_day 일
 * @return stirng 상세정보 html
 */
function schedule_user_get_event_view( $s_year, $s_mon, $s_day ) {
    global $wpdb;
    echo '<div class="user-event-view-date">'.$s_year."년 ".$s_mon."월 ".$s_day.'일</div>';
    $result_obj = $wpdb->get_results("SELECT * FROM wp_".EPART_SCHEDULE_NAME." WHERE ev_blogid = '".  get_current_blog_id()."' and (date_format(ev_startday,'%Y%m%d') <= '".$s_year.$s_mon.$s_day."' and date_format(ev_endday,'%Y%m%d') >= '".$s_year.$s_mon.$s_day."') order by ev_startday");    
    
    foreach($result_obj as $event_obj) {
        echo "<table id=\"user-event-view-table\" border=\"0\">";
        echo "<tr>";
        echo '<td class="user-event-field-name">제 목</td>';
        echo "<td>".$event_obj->ev_title."</td>";
        echo "</tr>";
        echo "<tr>";
        echo '<td class="user-event-field-name">시 간</td>';
        echo "<td>".substr($event_obj->ev_startday, 10) ." ~ ". substr($event_obj->ev_endday, 10) . "</td>";
        echo "</tr>";
        echo "<tr>";
        echo '<td class="user-event-field-name">장 소</td>';
        echo "<td>".$event_obj->ev_location."</td>";
        echo "</tr>";
        echo "<tr>";
        echo '<td class="user-event-field-name">내 용</td>';
        echo "<td>".$event_obj->ev_content."</td>";
        echo "</tr>";
        echo "</table>";
    }
    
    if( $result_obj == null ) {
        echo '<div class="user-event-none">등록된 일정이 없습니다.</div>';
    }
}
?>